package otcv.hr.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import otcv.hr.log.Logger;

/**
 * @author : H-Thien
 * @comment : Action class of upper class
 */
public abstract class ActionServlet {

	protected abstract String getURL();

	public abstract void process(ServletContext sc, HttpServletRequest request, HttpServletResponse response) throws Exception;

	/**
	 * @comment :
	 */
	public void forward(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		Logger.info("Using default forward");
		_dispatch(request, response);
	}

	/**
	 * @comment :
	 */
	protected void _dispatch(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		Logger.info("Redirecting to " + getURL());

		RequestDispatcher rd = request.getRequestDispatcher(getURL());
		if (rd == null) {
			Logger.warning("rd = null!");
		}
		rd.forward(request, response);
	}
}